function childNum(nums, count) {
    let allPlayer = []
    for (let i = 0; i < nums; i++) {
        allPlayer[i] = i + 1
    }

    let exitCount = 0, counter = 0, curIndex = 0
    while (exitCount < nums - 1) {
        if (allPlayer[curIndex] !== 0) counter++
        if (counter === count) {
            allPlayer[curIndex] = 0
            counter = 0
            exitCount++
        }

        if (++curIndex === nums) {
            curIndex = 0
        }
    }
    return allPlayer.find(child => child !== 0)
}

console.log(childNum(30, 3))